﻿# coding: utf-8

from Command import CCommand

import Transformation
import SceneNode

class CCmdAddModel(CCommand):
    """
    This command used to add a model to the scene.
    The model will be loaded from the specified file.
    """
    
    def __init__(self, **p):
        """
        Default class contructor.
        
        Parameters:
        @param fileName - model file path
        @param translation - relative translation
        @param rotation - relative rotation
        @param scaling - relative scaling
        """
        
        CCommand.__init__(self, TD.CMD_ADD_MODEL, **p)
        
    def DoCmd(self):
        try:
            fileName = self._paramDict['fileName']
            x, y, z = self._paramDict['translation']
            rx, ry, rz, rw = self._paramDict['rotation']
            sx, sy, sz = self._paramDict['scaling']
            self._modelNodeRef, entityHandle = SCENE_EDITOR.CreateModelSceneNode(fileName, True)
            node = self._modelNodeRef()
            Transformation.SetRelativeTranslation(SceneNode._CTransformation(node.GetCoreHandle()), x, y, z)
            Transformation.SetRelativeRotation(SceneNode._CTransformation(node.GetCoreHandle()), rx, ry, rz, rw)
            Transformation.SetRelativeScale(SceneNode._CTransformation(node.GetCoreHandle()), sx, sy, sz)
            
        except:
            SHOW_TRACE()
                
    def UndoCmd(self):
        try:
            modelNode = self._modelNodeRef()
            if not modelNode:
                return False
                
            SCENE_EDITOR.RemoveSceneNode(modelNode)
        
        except:
            SHOW_TRACE()

        return True